<?php	
	include('conn.php');
	session_start();
	error_reporting(E_ALL);	
	$msg='';
	$d = json_decode($_REQUEST['dataset']);
	$action = $_REQUEST['action'];		
	$inwarddate="$d->inwarddate";
	$proposalno="$d->proposalno";
	$policyno="$d->policyno";
	$filebarcode="$d->filebarcode";
	$cartonbarcode="$d->cartonbarcode";
	$awbno="$d->awbno";
	$courierid="$d->courierid";
	$districtid="$d->districtid";
	$remarks="$d->remarks";	    	  
	$enteredby = $_SESSION['username'];
	$entrydt = date("Y-m-d H:i:s");
	
	$sql1 = "select c.courierid, d.districtid from couriermast c, districtmast d
		where c.couriername = '$courierid' and d.districtname = '$districtid';";	
	$row = mysql_fetch_array(mysql_query($sql1));
	$courier = $row["courierid"];
	$district = $row["districtid"];
	
	switch($action)
	{
		case 'i':							
			$sql="insert into transactionmast (inwarddate, proposalno, policyno, filebarcode, cartonbarcode, awbno, courierid, districtid, remarks, enteredby, entrydt, status)
			values('$inwarddate','$proposalno','$policyno','$filebarcode','$cartonbarcode','$awbno','$courier','$district','$remarks','$enteredby','$entrydt','0')";
			
			echo $sql;
			$res=mysql_query($sql);
			if($res)
				$msg='Record saved successfully';			
			echo $msg;
			break;
		
		case 'u':
			$sql="update transactionmast set inwarddate='$inwarddate', proposalno='$proposalno', policyno='$policyno', filebarcode='$filebarcode', cartonbarcode='$cartonbarcode', awbno='$awbno', courierid='$courier', districtid='$district', remarks='$remarks' where trnid='$d->trnid';";
			
			echo $sql;
			$res=mysql_query($sql);
			if($res)
				$msg='Record saved successfully';			
			echo $msg;
			break;
		
		default:
			echo "No action selected... ";
	}    
?>